OpenStack Kilo : Add Virtual Machine Images
2015/06/07 |
Add Virtual Machine images in Glance.
|
|
[1] | Load environment variables first. |
[root@dlp ~]# unset OS_TOKEN OS_URL
[root@dlp ~]#
vi ~/keystonerc
export OS_PROJECT_DOMAIN_ID=default
export OS_USER_DOMAIN_ID=default export OS_PROJECT_NAME=admin export OS_TENANT_NAME=admin export OS_USERNAME=admin export OS_PASSWORD=adminpassword export OS_AUTH_URL=http://10.0.0.30:35357/v3 export PS1='[\u@\h \W(keystone)]\$ '
[root@dlp ~]#
chmod 600 ~/keystonerc [root@dlp ~]# source ~/keystonerc [root@dlp ~(keystone)]# echo "source ~/keystonerc " >> ~/.bash_profile
# display status (it's OK if no errors are shown) [root@dlp ~(keystone)]# glance image-list
+----+------+-------------+------------------+------+--------+ | ID | Name | Disk Format | Container Format | Size | Status | +----+------+-------------+------------------+------+--------+ +----+------+-------------+------------------+------+--------+ |
[2] | For example, Create a Virtual Machine image of CentOS 7. |
# create a disk image [root@dlp ~(keystone)]# qemu-img create -f qcow2 /var/kvm/images/centos7.img 10G
# install [root@dlp ~(keystone)]# virt-install \
Starting install...
--name centos7 \ --ram 2048 \ --disk path=/var/kvm/images/centos7.img,format=qcow2 \ --vcpus 2 \ --os-type linux \ --os-variant rhel7 \ --graphics none \ --console pty,target_type=serial \ --location 'http://ftp.iij.ad.jp/pub/linux/centos/7/os/x86_64/' \ --extra-args 'console=ttyS0,115200n8 serial' # installation starts |
[3] |
After installation, change settings in virtual machine like follows and shutdown it.
* delete or comment out the line "HWADDR" and "UUID" in /etc/sysconfig/network-scripts/ifcfg-eth0 * set "dhcp" for "BOOTPROTO" in /etc/sysconfig/network-scripts/ifcfg-eth0 |
[4] | Add the virtual image to Glance. |
[root@dlp ~(keystone)]# glance image-create --name="CentOS7" --is-public=true --disk-format=qcow2 --container-format=bare < /var/kvm/images/centos7.img +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | 3a995c048ab1ba84fc67533e46c896d5 | | container_format | bare | | created_at | 2015-06-07T13:36:28.000000 | | deleted | False | | deleted_at | None | | disk_format | qcow2 | | id | 5f187b29-3986-46d9-ab90-e0fa1d523d62 | | is_public | True | | min_disk | 0 | | min_ram | 0 | | name | CentOS7 | | owner | 0761e4ccdc1d45e38ec21237cbd652b5 | | protected | False | | size | 1015676928 | | status | active | | updated_at | 2015-06-07T13:36:33.000000 | | virtual_size | None | +------------------+--------------------------------------+[root@dlp ~(keystone)]# glance image-list +-----------+---------+-------------+------------------+------------+--------+ | ID | Name | Disk Format | Container Format | Size | Status | +-----------+---------+-------------+------------------+------------+--------+ | 5f187b29- | CentOS7 | qcow2 | bare | 1015676928 | active | +-----------+---------+-------------+------------------+------------+--------+ |
[5] | By the way, if you got an image from internet, it's OK to simply add it like follows. |
root@dlp:~#
root@dlp:~# wget http://cloud-images.ubuntu.com/releases/15.04/release/ubuntu-15.04-server-cloudimg-amd64-disk1.img -P /var/kvm/images
glance image-create --name="Ubuntu1504" --is-public=true --disk-format=qcow2 --container-format=bare < /var/kvm/images/ubuntu-15.04-server-cloudimg-amd64-disk1.img +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | 0ea22e8661eb533876eb903119cfa214 | | container_format | bare | | created_at | 2015-06-05T13:45:50 | | deleted | False | | deleted_at | None | | disk_format | qcow2 | | id | 872a3ac9-6e9d-4d7d-a7f1-56270c19047d | | is_public | True | | min_disk | 0 | | min_ram | 0 | | name | Ubuntu1504 | | owner | a521391a3fff4634ab11a18d06772ded | | protected | False | | size | 285213184 | | status | active | | updated_at | 2015-06-05T13:45:53 | | virtual_size | None | +------------------+--------------------------------------+ |